home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWExcLib / Sources / FWTryBlo.cpp < prev   
Encoding:
Text File  |  1995-11-08  |  3.3 KB  |  102 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTryBlo.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef FW_NATIVE_EXCEPTIONS
  13.  
  14. #ifndef   FWTRYBLO_H
  15. #include "FWTryBlo.h"
  16. #endif
  17.  
  18. #ifndef   FWEXCRUN_H
  19. #include "FWExcRun.h"
  20. #endif
  21.  
  22. #ifndef   FWDELSTA_H
  23. #include "FWDelSta.h"
  24. #endif
  25.  
  26. #if FW_LIB_EXPORT_PRAGMAS
  27. #pragma lib_export on
  28. #endif
  29.  
  30. #ifdef FW_BUILD_MAC
  31. #pragma segment BEL
  32. #endif
  33.  
  34. //========================================================================================
  35. // CLASS FW_CPrivTryBlockContext
  36. //========================================================================================
  37.  
  38. //----------------------------------------------------------------------------------------
  39. // FW_CPrivTryBlockContext::~FW_CPrivTryBlockContext
  40. //----------------------------------------------------------------------------------------
  41. FW_CPrivTryBlockContext::~FW_CPrivTryBlockContext()
  42. {
  43. #ifdef FW_DEBUG
  44.     CheckClassInvariants(fGlobals);
  45.     fGlobals.gContextDepth--;
  46.     FW_PRIV_ASSERT(fAutomaticsInMyScope == 0);
  47. #endif
  48.         
  49.     FW_CPrivTryBlockContext *priorContext = MakeCurrent(fGlobals, fPriorContext);
  50.     FW_PRIV_ASSERT(priorContext == this);
  51. }
  52.  
  53. //----------------------------------------------------------------------------------------
  54. // FW_CPrivTryBlockContext::FW_CPrivTryBlockContext
  55. //----------------------------------------------------------------------------------------
  56. FW_CPrivTryBlockContext::FW_CPrivTryBlockContext(FW_SPrivExceptionGlobals& globals, jmp_buf buffer) :
  57.     fGlobals(globals),
  58.     fJumpBuffer((jmp_buf *) buffer)
  59. {
  60.     fPriorContext = MakeCurrent(fGlobals, this);
  61.     fDeleteStackLevel = FW_CPrivDeleteStack::RelativeTopOfStack(fGlobals);
  62.  
  63. #ifdef FW_DEBUG
  64.     fGlobals.gContextDepth++;
  65.     fAutomaticsInMyScope = 0;
  66.     CheckClassInvariants(fGlobals);
  67. #endif
  68. }
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // FW_CPrivTryBlockContext::MakeCurrent
  72. //----------------------------------------------------------------------------------------
  73. class FW_CPrivTryBlockContext *FW_CPrivTryBlockContext::MakeCurrent(
  74.                                             FW_SPrivExceptionGlobals& globals,
  75.                                             FW_CPrivTryBlockContext *context)
  76. {
  77.     FW_CPrivTryBlockContext *tmpContext = globals.gCurrentContext;
  78.     globals.gCurrentContext = context;
  79.     return tmpContext;
  80. }
  81.  
  82. #ifdef FW_DEBUG
  83. //----------------------------------------------------------------------------------------
  84. // FW_CPrivTryBlockContext::CheckClassInvariants
  85. //
  86. //        Should only be called on current context.
  87. //----------------------------------------------------------------------------------------
  88. void FW_CPrivTryBlockContext::CheckClassInvariants(FW_SPrivExceptionGlobals& globals)
  89. {
  90.     // Ensure class invariants
  91.     FW_PRIV_ASSERT(&globals == &fGlobals);
  92.     FW_PRIV_ASSERT(globals.gContextDepth>=1);
  93.     FW_PRIV_ASSERT(globals.gContextDepth>1 || fPriorContext==NULL);
  94.     FW_PRIV_ASSERT(globals.gContextDepth==1 || fPriorContext!=NULL);
  95.     FW_PRIV_ASSERT(fAutomaticsInMyScope >= 0);
  96.     FW_PRIV_ASSERT(fDeleteStackLevel >= 0);
  97.     FW_PRIV_ASSERT(globals.gCurrentContext == this);
  98. }
  99. #endif
  100.  
  101. #endif // FW_NATIVE_EXCEPTIONS
  102.